'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    baseController = require('../../../Base/server/controllers/BaseDoc.js');

var menuModel = baseController.getBaseDocFields();
menuModel.Code = {
    type: String,
    unique: '编码已存在',
    required: '请输入编码',
    trim: true
};

menuModel.Name = {
    type: String,
    required: '请录入名称',
    trim: true
};

menuModel.URL = {
    type: String
};

menuModel.Parent = {
    type: Schema.ObjectId,
    ref: 'Menu'
};

var menuSchema = new Schema(menuModel);
menuSchema.index({Name: 1});
menuSchema.index({Code: 1}, {"unique": true});

mongoose.model('Menu', menuSchema, 'Menu');
